<?php
	include_once("DataProvider.php");
	include_once("../DTO/cauHinhSPDTO.php");
	
	class cauHinhSPDAO
	{
		public $sql = "";
		var $cauHinhSPDTO;
		function __construct()
		{
			return $this->cauHinhSPDTO = new cauHinhSPDTO();
		}
		
		public function load()
		{
			$result= DataProvider::ExecuteQuery($this->sql);
			$arrCauHinhSPDTO = new ArrayObject();
			
			while($row = mysql_fetch_array($result))
			{
				$cauHinhSPDTO = new cauHinhSPDTO();
				$cauHinhSPDTO->idCauHinhSP = $row['idCauHinhSP'];
				$cauHinhSPDTO->giaTri = $row['giaTri'];
				$cauHinhSPDTO->idCauHinhLoaiSP = $row['idCauHinhLoaiSP'];
				$cauHinhSPDTO->idSP = $row['idSP'];
				
				$arrCauHinhSPDTO[] = $cauHinhSPDTO;
			}
			return $arrCauHinhSPDTO;
		}
		
		public function load_CauHinhSP_All()
		{
			$this->sql= 'select * from cauhinhsp';
			$result=$this->load();
			return $result; 
		}
		
		public function load_CauHinhSP_One($idCauHinhSP)
		{
			$this->sql = 'select * from cauhinhsp where idCauHinhSP ='.$idCauHinhSP;
			$result = $this->load();
			return $result;
		}
		
		public function load_CauHinhSP_idLoaiSP($idLoaiSP)
		{
			$this->sql = "select * from cauhinhsp where idLoaiSP ='".$idLoaiSP."'";
			$result = $this->load();
			return $result;
		}
		
		public function themCauHinhSP($idSP, $gt)
		{
			$idTaiKhoan = $_SESSION["id"];
            $idCauHinhLoaiSP = $_POST['cmbLoaiSP'];
			$sql1 = "insert into cauhinhsp(idCauHinhSP, giaTri, idCauHinhLoaiSP, idSP) values(NULL, '$gt', '$idCauHinhLoaiSP', '$idSP')";	
			$result1 = DataProvider::ExecuteQuery($sql1);
			return $result1;
		}
		
		
	}
	
?>